package com.example.rbacmanage.controller;

import com.example.rbacmanage.annotation.LogAnnotation;
import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.entity.SysJobLog;
import com.example.rbacmanage.service.SysJobLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.example.rbacmanage.common.Result.success;

/**
 * 调度日志操作处理
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/monitor/jobLog")
public class SysJobLogController
{
    @Autowired
    private SysJobLogService sysJobLogService;

    /**
     * 查询定时任务调度日志列表
     */
    @PreAuthorize("hasAnyAuthority('monitor:jobLog:list')")
    @GetMapping("/list")
    public Result list(SysJobLog sysJobLog)
    {
        return Result.success(sysJobLogService.getPage(sysJobLog));
    }

    /**
     * 导出定时任务调度日志列表
     */
    @PreAuthorize("hasAnyAuthority('monitor:jobLog:export')")
    @LogAnnotation(module = "任务调度日志", operation = "导出定时任务调度日志列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysJobLog sysJobLog)
    {
        List<SysJobLog> list = sysJobLogService.getAll(sysJobLog);
//        ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class);
//        util.exportExcel(response, list, "调度日志");
    }
    
    /**
     * 根据调度编号获取详细信息
     */
    @PreAuthorize("hasAnyAuthority('monitor:jobLog:query')")
    @GetMapping(value = "/{jobLogId}")
    public Result getInfo(@PathVariable(value = "jobLogId") Long jobLogId)
    {
        return Result.success(sysJobLogService.getById(jobLogId));
    }


    /**
     * 删除定时任务调度日志
     */
    @PreAuthorize("hasAnyAuthority('monitor:jobLog:remove')")
    @LogAnnotation(module = "定时任务调度日志", operation = "删除定时任务调度日志")
    @DeleteMapping("/{jobLogIds}")
    public Result remove(@PathVariable(value = "jobLogIds") Long[] jobLogIds){
        sysJobLogService.remove(jobLogIds);
        return Result.success();
    }

    /**
     * 清空定时任务调度日志
     */
    @PreAuthorize("hasAnyAuthority('monitor:jobLog:remove')")
    @DeleteMapping("/clean")
    public Result clean()
    {
        sysJobLogService.cleanJobLog();
        return Result.success();
    }
}
